package edu.scu.declaresys.service.impl;

import java.util.List;

import edu.scu.declaresys.dao.DAOFactory;
import edu.scu.declaresys.dao.intr.IAreaDAO;
import edu.scu.declaresys.dao.util.Depth;
import edu.scu.declaresys.exception.ExecuteException;
import edu.scu.declaresys.service.intr.IAreaService;
import edu.scu.declaresys.vo.Area;

/**
 * 
 * @author: zt
 * @since : 2013-7-12
 */
public class AreaServiceImpl implements IAreaService
{
	private IAreaDAO areaDao = DAOFactory.createAreaDAO();
	
	@Override
	public Area findAreaById(Integer id, int depth) throws ExecuteException
	{
		return areaDao.findById(id, depth);
	}
	
	@Override
	public Area findByNameAndParent(Integer parentId, String areaName)
			throws ExecuteException
	{
		Area vo = new Area();
		vo.setName(areaName);
		vo.setParentId(parentId);
		return areaDao.findByExampleUnique(vo, Depth.ZERO);
	}
	
	@Override
	public List<Area> findAreaNextLevel(Integer parentId) throws ExecuteException
	{
		return areaDao.findByProperty(Area.T_PARENT_ID, parentId, 0, null, null, Area.T_ID, true);
	}

	@Override
	public Integer addArea(Area vo) throws ExecuteException
	{
		return areaDao.save(vo);
	}

	@Override
	public void modifyArea(Area vo, Integer id) throws ExecuteException
	{
		areaDao.update(vo, id);	
		return ;
	}

	@Override
	public void deleteArea(Integer id) throws ExecuteException
	{
		areaDao.delete(id);
		return ;
	}

	
}
